package com.wfx.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2 //开启swagger功能
public class Swagger2Configuration {


    private ApiInfo apiInfo() {


        Contact contact = new Contact("王润千","http://www.wendaoxueyuan.com","1910842366@qq.com");


        return new ApiInfoBuilder().title("微分销")
            .description("微分销-商户系统的-api接口文档")
            .version("1.0.0")
            .contact(contact)
            .build();


    }
    @Bean
    public Docket createRestApi(Environment environment) {

        //只有在dev环境或者sit环境才会显示swagger
        Profiles profiles = Profiles.of("dev","sit");
        boolean enable = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .enable(enable)
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.wfx")) //这里写的是API接口所在的包位置
            .paths(PathSelectors.any())
            .build();
    }
}